ostree_admin_option_context_parse: explicitly clean up when exiting early
authorSimon McVittie <smcv@debian.org>
Sun, 30 Oct 2016 14:14:09 +0000 (14:14 +0000)
committerAtomic Bot <atomic-devel@projectatomic.io>
Sun, 30 Oct 2016 21:37:38 +0000 (21:37 +0000)
The cleanup attribute doesn't clean up before calling a noreturn
function like exit(). Explicitly clean up the pointer variables
(but don't assume that a simple g_object_unref() would be OK either,
in case the behaviour of the cleanup attribute changes).

This isn't a real leak since we're about to exit anyway, but if we
don't fix it then valgrind memcheck will make the tests fail.

Signed-off-by: Simon McVittie <smcv@debian.org>
Closes: #559
Approved by: cgwalters

src/ostree/ot-main.c

index 18c1323960f72ac23658c7cd35ce2a7d0819e5d5..5080e8c61291438fde50c0badcc583823581388e 100644 (file)
@@ -366,6 +366,13 @@ ostree_admin_option_context_parse (GOptionContext *context,
 
       g_print ("%s\n", deployment_path);
 
+      /* The g_autoptr, g_autofree etc. don't happen when we explicitly
+       * exit, making valgrind complain about leaks */
+      g_clear_object (&sysroot);
+      g_clear_object (&sysroot_path);
+      g_clear_object (&deployment_file);
+      g_clear_pointer (&deployments, g_ptr_array_unref);
+      g_clear_pointer (&deployment_path, g_free);
       exit (EXIT_SUCCESS);
     }